import 'package:flutter/material.dart';

class InputWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => new _InputWidget();
}

class _InputWidget extends State<InputWidget> {
  final TextEditingController _controller = new TextEditingController();
  String inputStr = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: new Text('文本输入'),
        leading: BackButton(),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Text(inputStr),
          new TextField(
            controller: _controller,
            decoration: new InputDecoration(
              hintText: '请输入信息',
            ),
            onChanged: (String str) {
              setState(() {
                inputStr = str;
              });
            },
          ),
          new ElevatedButton(
            onPressed: () {
              showDialog(
                  context: context,
                  builder: (BuildContext context) => new AlertDialog(
                        title: Text('你的输入：'),
                        content: Text(_controller.text),
                      ));
            },
            child: Text('DONE'),
          ),
        ],
      ),
    );
  }
}
